package com.spddr.pmos.cxf.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.spddr.pmos.cxf.JaxrsUnitWaterCost;
import com.spddr.pmos.jpa.UnitWaterCost;
import com.spddr.pmos.jpa.UnitWaterCostId;
import com.spddr.pmos.repos.UnitWaterCostRepos;

@Service
public class JaxrsUnitWaterCostImpl implements JaxrsUnitWaterCost {
	@Autowired
	private UnitWaterCostRepos repository;

	@Override
	public JpaRepository<UnitWaterCost, UnitWaterCostId> getRepository() {
		return repository;
	}

	@Override
	public List<UnitWaterCost> findByUnit(long unit) {
		return repository.findByIdUnit(unit);
	}

	@Override
	public void saveByUnit(long unit, List<UnitWaterCost> entities) {
		repository.save(entities.stream()
				.peek(x -> x.getId()
						.setUnit(unit))
				.collect(Collectors.toList()));
	}

	@Override
	public void deleteByUnit(long unit) {
	}
}
